package cn.kjcoder.productServer.web.controller;

import cn.kjcoder.productServer.domain.Product;
import cn.kjcoder.productServer.service.IProductService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author hkj
 * @email 1349091387@qq.com
 * @date 2021/12/21
 * 源码允许修改，并且本人十分乐意有 大佬 来对代码进行 随 意 调 教
 **/
@RestController
@Slf4j
public class ProductController {

    @Autowired
    private IProductService productService;
    @Value("${server.port}")
    private String port;

    @RequestMapping("/product/get")
    public Product findById(@RequestParam("id") Long id){
        log.info("商品表现层调用");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("接下来要进行{}号商品信息的查询", id);
        Product product = productService.findById(id);
        product.setPname(product.getPname()+",data from "+port);
        log.info("商品信息查询成功,内容为{}", JSON.toJSONString(product));
        return product;
    }
}
